package fr.gla.hibtracker.historique.collection;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import org.hibernate.HibernateException;
import org.hibernate.collection.PersistentCollection;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.usertype.UserCollectionType;

public class HistoricCollectionType implements UserCollectionType{

	private Set<?> getCollection(Object collection) {
		return (Set<?>)collection;
	}
	
	public boolean contains(Object collection, Object entity) {
		return getCollection(collection).contains(entity);
	}

	public Iterator getElementsIterator(Object collection) {
		return getCollection(collection).iterator();
	}

	public Object indexOf(Object collection, Object entity) {
		return null;
	}

	public Object instantiate(int anticipatedSize) {
		return new HashSet();
	}

	public PersistentCollection instantiate(SessionImplementor session,
			CollectionPersister persister) throws HibernateException {
		return new HistoricCollection(session);
	}

	public Object replaceElements(Object original, Object target,
			CollectionPersister persister, Object owner, Map copyCache,
			SessionImplementor session) throws HibernateException {
		return null;
	}

	public PersistentCollection wrap(SessionImplementor session,
			Object collection) {
		return new HistoricCollection(session,getCollection(collection));
	}

}
